﻿
namespace Patterns4Net.Core.Patterns
{
    using System;
    using Patterns4Net.Attributes;

    /// <summary>
    /// Base class for all patterns.
    /// Overrides <see cref="Equals"/> and <see cref="GetHashCode"/> because most patterns 
    /// do not have any properties their equality is based only on type equality.
    /// </summary>
    public abstract class PatternBase : IPattern
    {
        /// <summary>
        /// Gets the name of the pattern.
        /// Default implementation returns the name of the pattern class, 
        /// which is in most cases sufficient.
        /// </summary>
        public virtual string Name
        {
            get { return this.GetType().Name; }
        }

        public virtual AbstractionLevel? AbstractionLevel
        {
            get { return null; }
        }

        public override bool Equals(object obj)
        {
            return obj != null && this.GetType() == obj.GetType();
        }

        public override int GetHashCode()
        {
            return this.GetType().GetHashCode();
        }
    }
}
